package com.j.lemon.learn.thread;

/**
 * @Author lijunjun
 * @Date 2019-06-05 11:15
 * @Description
 */
public class SynchronizedPrinciple {
    private synchronized void test1() throws InterruptedException {
        System.out.println("1");
        Thread.sleep(3000);
        System.out.println("1.1");
    }

    private synchronized void test2() throws InterruptedException {
        System.out.println("2");
        Thread.sleep(3000);
        System.out.println("2.2");
    }

    private void test3() throws InterruptedException {
        System.out.println("3");
        Thread.sleep(3000);
        System.out.println("3.3");
    }

    public static void main(String[] args) {
        SynchronizedPrinciple synchronizedPrinciple = new SynchronizedPrinciple();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    synchronizedPrinciple.test1();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    synchronizedPrinciple.test2();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    synchronizedPrinciple.test3();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }


}
